home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 April / PCWorld_1999-04_cd.bin / Software / Vyzkuste / LearnVB5 / VB Code / Class 2 / Exercise2-2.frm (.txt) < prev    next >
Visual Basic Form  |  1998-04-10  |  7KB  |  231 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAdd 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Flash Card Addition"
  5.    ClientHeight    =   2955
  6.    ClientLeft      =   2070
  7.    ClientTop       =   1500
  8.    ClientWidth     =   5370
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    PaletteMode     =   1  'UseZOrder
  13.    ScaleHeight     =   2955
  14.    ScaleWidth      =   5370
  15.    Begin VB.CommandButton cmdNext 
  16.       Caption         =   "&Next Problem"
  17.       Enabled         =   0   'False
  18.       Height          =   495
  19.       Left            =   2280
  20.       TabIndex        =   9
  21.       Top             =   2400
  22.       Width           =   1335
  23.    End
  24.    Begin VB.CommandButton cmdExit 
  25.       Caption         =   "E&xit"
  26.       Height          =   495
  27.       Left            =   4440
  28.       TabIndex        =   5
  29.       Top             =   2400
  30.       Width           =   855
  31.    End
  32.    Begin VB.TextBox txtAnswer 
  33.       BeginProperty Font 
  34.          Name            =   "Arial"
  35.          Size            =   48
  36.          Charset         =   0
  37.          Weight          =   400
  38.          Underline       =   0   'False
  39.          Italic          =   0   'False
  40.          Strikethrough   =   0   'False
  41.       EndProperty
  42.       Height          =   1200
  43.       Left            =   3960
  44.       MaxLength       =   2
  45.       TabIndex        =   4
  46.       Top             =   120
  47.       Width           =   1215
  48.    End
  49.    Begin VB.Label lblMessage 
  50.       Alignment       =   2  'Center
  51.       BackColor       =   &H00FFFF00&
  52.       BorderStyle     =   1  'Fixed Single
  53.       BeginProperty Font 
  54.          Name            =   "MS Sans Serif"
  55.          Size            =   24
  56.          Charset         =   0
  57.          Weight          =   700
  58.          Underline       =   0   'False
  59.          Italic          =   -1  'True
  60.          Strikethrough   =   0   'False
  61.       EndProperty
  62.       Height          =   615
  63.       Left            =   1560
  64.       TabIndex        =   8
  65.       Top             =   1560
  66.       Width           =   3735
  67.    End
  68.    Begin VB.Label lblScore 
  69.       Alignment       =   2  'Center
  70.       BackColor       =   &H0000FFFF&
  71.       BorderStyle     =   1  'Fixed Single
  72.       Caption         =   "0"
  73.       BeginProperty Font 
  74.          Name            =   "Times New Roman"
  75.          Size            =   36
  76.          Charset         =   0
  77.          Weight          =   700
  78.          Underline       =   0   'False
  79.          Italic          =   0   'False
  80.          Strikethrough   =   0   'False
  81.       EndProperty
  82.       Height          =   855
  83.       Left            =   120
  84.       TabIndex        =   7
  85.       Top             =   1920
  86.       Width           =   1215
  87.    End
  88.    Begin VB.Label Label1 
  89.       Alignment       =   2  'Center
  90.       Caption         =   "Score:"
  91.       BeginProperty Font 
  92.          Name            =   "MS Sans Serif"
  93.          Size            =   18
  94.          Charset         =   0
  95.          Weight          =   400
  96.          Underline       =   0   'False
  97.          Italic          =   0   'False
  98.          Strikethrough   =   0   'False
  99.       EndProperty
  100.       Height          =   375
  101.       Left            =   120
  102.       TabIndex        =   6
  103.       Top             =   1440
  104.       Width           =   1095
  105.    End
  106.    Begin VB.Label Label4 
  107.       Alignment       =   2  'Center
  108.       Caption         =   "="
  109.       BeginProperty Font 
  110.          Name            =   "Arial"
  111.          Size            =   48
  112.          Charset         =   0
  113.          Weight          =   400
  114.          Underline       =   0   'False
  115.          Italic          =   0   'False
  116.          Strikethrough   =   0   'False
  117.       EndProperty
  118.       Height          =   975
  119.       Left            =   3240
  120.       TabIndex        =   3
  121.       Top             =   120
  122.       Width           =   615
  123.    End
  124.    Begin VB.Label lblNum2 
  125.       Alignment       =   2  'Center
  126.       BeginProperty Font 
  127.          Name            =   "Arial"
  128.          Size            =   48
  129.          Charset         =   0
  130.          Weight          =   400
  131.          Underline       =   0   'False
  132.          Italic          =   0   'False
  133.          Strikethrough   =   0   'False
  134.       EndProperty
  135.       Height          =   1095
  136.       Left            =   2040
  137.       TabIndex        =   2
  138.       Top             =   120
  139.       Width           =   1095
  140.    End
  141.    Begin VB.Label Label2 
  142.       Alignment       =   2  'Center
  143.       Caption         =   "+"
  144.       BeginProperty Font 
  145.          Name            =   "Arial"
  146.          Size            =   48
  147.          Charset         =   0
  148.          Weight          =   400
  149.          Underline       =   0   'False
  150.          Italic          =   0   'False
  151.          Strikethrough   =   0   'False
  152.       EndProperty
  153.       Height          =   975
  154.       Left            =   1320
  155.       TabIndex        =   1
  156.       Top             =   120
  157.       Width           =   615
  158.    End
  159.    Begin VB.Label lblNum1 
  160.       Alignment       =   2  'Center
  161.       BeginProperty Font 
  162.          Name            =   "Arial"
  163.          Size            =   48
  164.          Charset         =   0
  165.          Weight          =   400
  166.          Underline       =   0   'False
  167.          Italic          =   0   'False
  168.          Strikethrough   =   0   'False
  169.       EndProperty
  170.       Height          =   1095
  171.       Left            =   120
  172.       TabIndex        =   0
  173.       Top             =   120
  174.       Width           =   1095
  175.    End
  176. Attribute VB_Name = "frmAdd"
  177. Attribute VB_GlobalNameSpace = False
  178. Attribute VB_Creatable = False
  179. Attribute VB_PredeclaredId = True
  180. Attribute VB_Exposed = False
  181. Option Explicit
  182. Dim Sum As Integer
  183. Dim NumProb As Integer, NumRight As Integer
  184. Private Sub cmdExit_Click()
  185. End Sub
  186. Private Sub cmdNext_Click()
  187. 'Generate next addition problem
  188. Dim Number1 As Integer
  189. Dim Number2 As Integer
  190. txtAnswer.Text = ""
  191. lblMessage.Caption = ""
  192. NumProb = NumProb + 1
  193. 'Generate random numbers for addends
  194. Number1 = Int(Rnd * 21)
  195. Number2 = Int(Rnd * 21)
  196. lblNum1.Caption = Format(Number1, "#0")
  197. lblNum2.Caption = Format(Number2, "#0")
  198. 'Find sum
  199. Sum = Number1 + Number2
  200. cmdNext.Enabled = False
  201. txtAnswer.SetFocus
  202. End Sub
  203. Private Sub Form_Activate()
  204. Call cmdNext_Click
  205. End Sub
  206. Private Sub Form_Load()
  207. Randomize Timer
  208. NumProb = 0
  209. NumRight = 0
  210. End Sub
  211. Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
  212. Dim Ans As Integer
  213. 'Check for number only input and for return key
  214. If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Then
  215.   Exit Sub
  216. ElseIf KeyAscii = vbKeyReturn Then
  217. 'Check answer
  218.   Ans = Val(txtAnswer.Text)
  219.   If Ans = Sum Then
  220.     NumRight = NumRight + 1
  221.     lblMessage.Caption = "That's correct!"
  222.   Else
  223.     lblMessage.Caption = "Answer is " + Format(Sum, "#0")
  224.   End If
  225.   lblScore.Caption = Format(100 * NumRight / NumProb, "##0")
  226.   cmdNext.Enabled = True
  227.   cmdNext.SetFocus
  228.   KeyAscii = 0
  229. End If
  230. End Sub
  231.